﻿#pragma once

#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QInputDialog>
#include <QMessageBox>
#include <QMouseEvent>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QTimer>
#include <QtWidgets/QMainWindow>

// 取消宏定义
#undef foreach
#undef near

// 读写头文件
#include <IGESControl_Reader.hxx>
#include <IGESControl_Writer.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>

// 交互头文件
#include <AIS_PointCloud.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Triangulation.hxx>

// 形状头文件
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>

// 几何头文件
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>

// BRep 头文件
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>

#include <learn/utils/obj_tool.h>
#include <learn/utils/adaptor_occ.h>

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

  public:
    friend class OCCWidget;
    friend class CtrlWidget;

    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void add_point_cloud(const std::vector<gp_Pnt> &points);             // 添加点云
    void add_curve(Handle(Geom_Curve) curve, double first, double last); // 添加曲线
    void add_surface(Handle(Geom_Surface) surface);                      // 添加曲面
    void add_shape(const TopoDS_Shape &shape);                           // 用于载入形状
    void add_triangulation(Handle(Poly_Triangulation) triangulation);    // 用于载入三角化

    void read_stp(const char *path);
    void write_stp(const char *path);
    void read_igs(const char *path);
    void write_igs(const char *path);
    void read_brep(const char *path);
    void write_brep(const char *path);
    void read_cloud(const char *path);
    void write_cloud(const char *path);
    void read_obj(const char *path);
    void write_obj(const char *path);

    void show_message(std::string msg); // 在状态栏显示消息

    OCCWidget *occ_widget();
    CtrlWidget *ctrl_widget();

    // 用于设置两个子窗口的大小和位置
    virtual void resizeEvent(QResizeEvent *event);

  public slots:
    void initializeChildren();

    void openFile();
    void openCloud();
    void openDirectory();
    void saveFile();
    void saveCloud();
    void deleteFile();

    void coverFPIA();
    void coverEnergy();
    void coverCoons();
    void coverDBS();

    void computeDistance();
    void computeEnergy();
    void rangeWeight();
    void discrete();

  private:
    Ui::MainWindow *ui;

    std::vector<TopoDS_Shape> m_selected;                     // 存放被选中的拓扑
    std::vector<TopoDS_Shape> m_shapes;                       // 存放拓扑形状
    std::vector<Handle(AIS_PointCloud)> m_clouds;             // 存放点云
    std::vector<Handle(Poly_Triangulation)> m_triangulations; // 存放三角化
};
